﻿using CourseManageUI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CourseManagerUI
{
	public partial class FrmMain : Form
	{
		public FrmMain()
		{
			InitializeComponent();
            //显示当前登录用户名
            this.CurrentUserlabel.Text = Program.currentTeacher.TeacherName;

		}

        #region 窗体移动代码
        private Point mouseOff;//鼠标移动位置变量
        private bool leftFlag;//标签是否为左键
        private void Frm_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                mouseOff = new Point(-e.X, -e.Y); //得到变量的值
                leftFlag = true;                  //点击左键按下时标注为true;
            }
        }
        private void Frm_MouseMove(object sender, MouseEventArgs e)
        {
            if (leftFlag)
            {
                Point mouseSet = Control.MousePosition;
                mouseSet.Offset(mouseOff.X, mouseOff.Y);  //设置移动后的位置
                Location = mouseSet;
            }
        }
        private void Frm_MouseUp(object sender, MouseEventArgs e)
        {
            if (leftFlag)
            {
                leftFlag = false;//释放鼠标后标注为false;
            }
        }

		#endregion

		#region 窗体嵌入子窗体代码
        private void OpenForm(Form childForm)
		{
            //添加的空间都会放入Controls集合中，所有从panel容器的controls的中取出
            foreach (Control control in this.FrmMainPanel3.Controls)
            {
                if (control is Form)
                {
                    ((Form)control).Close();
                }
            }

            childForm.TopLevel = false;//子窗体设置为非顶级控件
            childForm.Parent = this.FrmMainPanel3;//设置窗体容器
            childForm.Dock = DockStyle.Fill;//随着容器大小自动调整子窗体大小

            childForm.Show();
        }

		#endregion

		//点击课程信息管理按钮
		private void CourseMessageBtn_Click(object sender, EventArgs e)
		{
			OpenForm(new FrmCourseManage());
		}

		private void CloseFrmMainBtn_Click(object sender, EventArgs e)
		{
            this.Close();
		}

		private void AddCourseBtn_Click(object sender, EventArgs e)
		{
            OpenForm(new FrmAddCourse());
		}
	}
}
